/**
 * @description utils api 路由
 */

const router = require('koa-router')()
const { loginCheck } = require('../../middlewares/loginChecks')
const koaForm = require("formidable-upload-koa");
const { saveFile } = require('../../controller/utils');

router.prefix('/api/utils')

//上传图片
router.post('/upload',loginCheck,koaForm(), async (ctx,next) => {
  const file = ctx.req.files['file']; // 在ctx.req.files里获取到上传的文件，['file']是前端input上传文件组件的name属性值
  if(!file){
    return
  }
  const { size,path,name,type } = file; // file 里面的参数
  //controller
  ctx.body = await saveFile({
    name,
    type,
    size,
    filePath:path
  })
})

module.exports = router